
function setDataLand(category,site_id){
	Ext.Ajax.request({
	    method: "GET",
	    dataType: "json",
	    url: "./Services/Asset/AssetSACDetails?cat="+category+"&siteid="+site_id+"",
	    async: false	,
	    success: function(c) {
	    	var jsonResults= $.parseJSON(c.responseText);
	    	data = jsonResults.item[0];
	    	Ext.getCmp('formAssetLand').getForm().setValues(data);
        }
    });	       

	
}


function InputDataLand(){	
	Ext.getCmp('formAssetLand').getForm().submit({        	        				  
		success: function(form, action) {
			Ext.Msg.alert('Submited', action.response.responseText);
		},
		failure: function(form, action) {
			Ext.Msg.alert('Submited', action.response.responseText);
		}
	});
}

function popupLandPbb() {
	  var win = new Ext.Window({
	        modal : true,
	        height : 0.4 * screen.height,
	        width : 1080,
	        border : false,
	        resizable : false,
	        closable : true,
	        title : 'Nomor Objek Pajak',
	        layout : 'fit',
	        titleAlign : 'center',
	        frame : true,
	        autoScroll : true,
	        listeners: {
	          	afterrender: function () {
	              	Ext.getCmp('assetIdLandPbb').setValue(Ext.getCmp('assetIdLand').getValue());   
	              	var assetId = Ext.getCmp("assetIdLandPbb").getValue();
					Ext.getStore('AssetDataMaster.AssetLandPbb').removeAll();
					Ext.getStore('AssetDataMaster.AssetLandPbb').getProxy().url = './Services/Asset/AssetLandPbb/List?assetId=' + assetId;
					Ext.getStore('AssetDataMaster.AssetLandPbb').load();
					Ext.getStore('AssetDataMaster.AssetLandPbb').on({
						load:function(){
						var store = Ext.getStore('AssetDataMaster.AssetLandPbb').getAt(0);
						if(store != null){
							Ext.getCmp('noobjpajak').setValue(store.get('PBB_NO'));
						}
					}
					});
				}
					
	      	},
	        items : [
	             {
	                xtype: 'form',
	                id: 'formAssetLandPbb',
	                width: 1080,
	                heigth: 100,
	                layout: 'hbox',
	                border: false,
	                method: 'POST',
	                url: './Services/Asset/AssetLandPbb/Add',
	                margin: '0 10 0 0',
	                items: [
	                    {
	                        xtype: 'panel',
	                        width: 310,
	                        heigth:  0.7 * screen.height,
	                        layout: 'vbox',
	                        border: false,
	                        margin: '10 10 10 10',
	                        items: [
                                {
		                            xtype: 'hiddenfield',
		                            cls: 'black',
		                            id : 'pbbIdLandPbb',
		                            name: 'SITE_LAND_PBB_HISTORY_ID',
		                            margin: '5 10 5 25',
		                            labelWidth: 130 / 1366 * screen.width,
		                            width: 300 / 1366 * screen.width,
		                            fieldLabel: 'PBB ID',
		                            msgTarget: 'title',
		                            allowBlank: true,
		                            validateBlank: false
		
		                        },
		                        {
		                            xtype: 'hiddenfield',
		                            cls: 'black',
		                            id : 'assetIdLandPbb',
		                            name: 'ASSET_DETAIL_ID',
		                            margin: '5 10 5 25',
		                            labelWidth: 130 / 1366 * screen.width,
		                            width: 300 / 1366 * screen.width,
		                            fieldLabel: 'Asset ID',
		                            msgTarget: 'title',
		                            allowBlank: true,
		                            validateBlank: false
		
		                        },
	                            {
			                        xtype: 'textfield',
			                        cls: 'black',
			                        name: 'NOP',
			                        margin: '0 10 10 5',
			                        labelWidth: 100 / 1366 * screen.width,
			                        width: 300 / 1366 * screen.width,
			                        fieldLabel: 'No Obyek Pajak ',
			                        msgTarget: 'title',
			                        allowBlank: true,
			                        validateBlank: false
			
			                    },
	                            {
			                        xtype: 'datefield',
			                        cls: 'black',
			                        name: 'PBB_DUE_DATE',
			                        margin: '0 10 10 5',
									format : 'Y/m/d',
			                        labelWidth: 100 / 1366 * screen.width,
			                        width: 300 / 1366 * screen.width,
			                        fieldLabel: 'PBB Due Date',
			                        msgTarget: 'title',
			                        allowBlank: true,
			                        validateBlank: false
			
			                    },
	                            {
			                        xtype: 'textfield',
			                        cls: 'black',
			                        name: 'PBB_AMOUNT',
			                        margin: '0 10 10 5',
			                        labelWidth: 100 / 1366 * screen.width,
			                        width: 300 / 1366 * screen.width,
			                        fieldLabel: 'PBB Amount',
			                        msgTarget: 'title',
			                        allowBlank: true,
			                        validateBlank: false
			
			                    },
			                    {
	                                xtype: 'combobox',
	                                cls: 'black',
	                                name: 'PAYMENT_STATUS',
	                                margin: '0 10 10 5',
	                                labelWidth: 100 / 1366 * screen.width,
	                                width: 300 / 1366 * screen.width,
	                                fieldLabel: 'Payment Status',
	                                emptyText: 'Payment Status',
	                                msgTarget: 'title',
	                                allowBlank: true,
	                                forceSelection: true,
	                                store: [['True', 'Yes'], ['False', 'No']]
	                            },
	                            {
			                        xtype: 'datefield',
			                        cls: 'black',
			                        name: 'PAYMENT_DATE',
			                        margin: '0 10 10 5',
									format : 'Y/m/d',
			                        labelWidth: 100 / 1366 * screen.width,
			                        width: 300 / 1366 * screen.width,
			                        fieldLabel: 'Payment Date',
			                        msgTarget: 'title',
			                        allowBlank: true,
			                        validateBlank: false
			
			                    },
			                    {
				   		             xtype: 'fileuploadfield',
				   		             id: 'docPbb',
				   		             emptyText: 'Select a document to upload...',
				   		             name:'FILE',
				   		             fieldLabel: 'Document',
				   		             buttonText: '...',
				   		             labelWidth: 100/1366*screen.width,
				   		             width: 300/1366*screen.width,
				   		             margin:'0 10 10 5'
			                    },
			                    {
	                                xtype: 'combobox',
	                                cls: 'black',
	                                name: 'ENABLED',
	                                margin: '0 10 10 5',
	                                labelWidth: 100 / 1366 * screen.width,
	                                width: 300 / 1366 * screen.width,
	                                fieldLabel: 'Active',
	                                emptyText: 'Active',
	                                store: [['True', 'Yes'], ['False', 'No']],
	                                msgTarget: 'title',
	                                allowBlank: true,
	                                validateBlank: false
	                            },
	                            {
                                    xtype: 'panel',
                                    width: 345,
                                    heigth: 100,
                                    layout: 'hbox',
                                    border: false,
                                    margin: '0 10 0 0',
                                    items: [
                                        {
                                            xtype: 'button',
                                            width: 60,
                                            height: 30,
                                            margin: '0 10 0 110',
                                            text: 'Add',
                                            id: 'btnSubmitLandPbb',
                                            handler: function () {
                                                Ext.getCmp('formAssetLandPbb').getForm().submit({
                                                	 waitMsg : 'Please Wait ....',
													success: function(form, action) {
														Ext.Msg.alert('Submited', action.response.responseText);
													},
													failure: function(form, action) {
														Ext.Msg.alert('Submited', action.response.responseText);
														Ext.getStore('AssetDataMaster.AssetLandPbb').load();
													}
												});
                                            }
                                        },
                                        {
                                            xtype: 'button',
                                            width: 60,
                                            height: 30,
                                            margin: '0 10 0 45',
                                            text: 'Cancel',
                                            id: 'btnCancelLandPbb',
                                            handler: function () {
                                                Ext.getCmp('formAssetLand').getForm().reset;
                                                Ext.getStore('AssetDataMaster.AssetLandPbb').load();
                                            }
                                        }
                                    ]
                                }
	                        ]
	                    },
	                    {
			            	 xtype : 'gridpanel',
			            	 id : 'gridAssetLandPbb',
			            	 height : 0.33 * screen.height,
			            	 autoScroll : 'true',
			            	 width : 700,
//			            	 selType : 'checkboxmodel',
			            	 region : 'center',
			            	 columnLines : true,
	                         margin: '10 10 10 10',
			            	 //forceFit : true,
			            	 store : 'AssetDataMaster.AssetLandPbb',
			            	 listeners : {
			        	 		afterrender : function() {
									
			             	 	}
			      			 },
					          columns: [
					              {dataIndex: 'PBB_NO', text: 'PBB NO', align: 'left'},
					              {dataIndex: 'PBB_DUE_DATE', text: 'PBB DUE DATE', align: 'left'},
					              {dataIndex: 'PBB_AMOUNT', text: 'PBB AMOUNT', align: 'left'},
					              {dataIndex: 'PAYMENT_STATUS', text: 'PAYMENT STATUS', align: 'left'},
					              {dataIndex: 'PAYMENT_DATE', text: 'PAYMENT DATE', align: 'left'},
					              {
			                      	    xtype: 'actioncolumn',
			                      	    text : 'DOCUMENT',
			                      	    align : 'center',
			                      	    renderer: function (value, metadata, record) {
			                      	    	var document = record.get('ATTACH_FILE');
			                      	    	if (document=="null"){
			                      	    		this.items[0].icon = '';
			                      	    	}else{
			                      	    		var typefile=document.split(".");
			                      	    		 if (typefile[1]=="pdf"){ 
			                      	    			 this.items[0].icon = 'images/pdf-icon.png'; 
			                      	    		 }else if (typefile[1]=="docx" || typefile[1]=="doc"){
			                      	    			 this.items[0].icon = 'images/Word-icon.png';  
			                      	    		 }else if (typefile[1]=="xlsx" || typefile[1]=="xls"){ 
			                      	    			 this.items[0].icon = 'images/Excel-icon.png';  
			                      	    		 }else if (typefile[1]=="jpeg" || typefile[1]=="xls"){ 
			                      	    			 this.items[0].icon = 'images/images-icon.jpg';  
			                      	    		 }
			                      	    	}
			                      	    },
			                      	    items: [{
			                      	        tooltip: 'Show Document',
			                      	        handler: function (grid, rowIndex, colIndex) {
			                      	        	 var rec = grid.getStore().getAt(rowIndex);
			                      	        	 var typefile=rec.get('ATTACH_FILE').split(".");
			                      	        	 console.log (rec.get('ATTACH_FILE'));
			                      	        	 if (typefile[1]=="pdf"){
			                      	        		window.open('./Services/Asset/doc/pdf/'+rec.get('ATTACH_FILE')); 
			                      	        	 }else{
			                      	        		 window.open('./Services/Asset/doc/img/'+rec.get('ATTACH_FILE'));  
			                      	        	 }
			                      	        }
			                      	    }]
					              },
					              {dataIndex: 'ENABLED', text: 'ENABLED', align: 'left'}
					          ],
				      			listeners : {
					                itemdblclick : function(grid, record) {
					                	var pbbId = record.get('SITE_LAND_PBB_HISTORY_ID');
					                	console.log (pbbId);
				                		Ext.Ajax.request({
				                		    method: "GET",
				                		    dataType: "json",
				                		    url: "./Services/Asset/AssetLandPbb/"+pbbId,
				                		    async: false	,
				                		    success: function(c) {
				                		    	var jsonResults= $.parseJSON(c.responseText);
				                		    	data = jsonResults.item[0];
				                		    	console.log (data);
				                		    	Ext.getCmp('formAssetLandPbb').getForm().setValues(data);
				                		    	Ext.getCmp('btnSubmitLandPbb').setText('Update');	
			                		        }
			                		    });	
					                }
			      			 	}	  
			            }   
	                ] 
	            }
	                
	         ]
	      }).show();

	}

